﻿import com.dmotiko.mirador.*
import com.dmotiko.general.*
import mx.utils.Delegate;

class MiradorHome
extends MiradorSiteSection {
	private var mcButtonBar:MiradorMainBtnBar;
	
	function MiradorHome() {
		super( MiradorSite.getApp() );
		sName = MiradorSite.HOME;
		sectionChanged();
	}
	
	private function sectionChanged(evnt) {
		if( getData().getSection() != MiradorSite.PREHOME) {
			showSection();
		} else {
			hideSection();
		}
	}
	
	public function showSection() {
		if (bShowed) return;
		bShowed = true;
		this.gotoAndStop(2);
		showEnd();
	}
	
	public function hideSection() {
		if (!bShowed) return;
		bShowed = false;
		this.gotoAndStop(1);
		hideEnd();
	}
	
	public function childLoaded( evnt ):Void {
		if ( evnt.target == mcButtonBar) {
			mcButtonBar.addEventListener( BaseClipEvent.CHANGED, Delegate.create(this, buttonbar_changed));
		}
	}
	
	private function buttonbar_changed( evnt ):Void {
		//MiradorSite.getApp().log( "MiradorHome | buttonnbar_changed= "+evnt.data );
		MiradorSite.getApp().setSection( evnt.data );
	}
}